<template>
  <div class="tag">
    <!--    头部-->
    <div class="head">
      <el-form ref="form" :inline="true" :model="selectData" label-width="100px">
<!--        <el-form-item label="商家名称">-->
<!--          <el-input v-model="selectData.name" placeholder="请输入商家名称"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="状态">
          <el-select v-model="selectData.status" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="success" @click="select">查询</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="body">
      <el-table
        v-loading="isLoading"
        :stripe="true"
        :data="tableData"
        style="width: 100%">
        <el-table-column
          prop="name"
          label="姓名"
          align="center">
        </el-table-column>
        <el-table-column
          prop="address"
          label="地址"
          align="center">
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.is_examine == 0" type="info">待审</el-tag>
            <el-tag v-else-if="scope.row.is_examine == 9" type="success">通过</el-tag>
            <el-tag v-else-if="scope.row.is_examine == 1" type="danger">驳回</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="编辑"
          align="center">
          <template slot-scope="scope">
            <el-button type="primary" @click="checkShop(scope.row)">查看</el-button>
            <el-button type="success" @click="auditshop(scope.row)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="body-page">
        <el-pagination
          :current-page="1"
          :page-sizes="[10, 20, 30, 50]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

<!--  审核商家  -->
    <el-dialog
      title="审核商家"
      :visible.sync="auditDialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-form ref="auditForm" :model="auditDialogData" :rules="rules">
        <el-form-item label="审核商家" prop="status">
          <el-select v-model="auditDialogData.is_examine" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="text-align: right">
          <el-button type="primary" @click="submitAudit('auditForm')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
<!--  查看商家信息  -->
    <!--  查看信息弹出框  -->
    <el-dialog
      title="商家信息"
      :visible.sync="checkDialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="商家信息" name="first">
          <el-form ref="form" :model="checkDialogData">
            <el-form-item label="商家姓名">
              <el-input disabled="true" v-model="checkDialogData.name"></el-input>
            </el-form-item>
            <el-form-item label="商家地址">
              <el-input disabled="true" v-model="checkDialogData.address"></el-input>
            </el-form-item>
            <el-form-item label="商家描述">
              <el-input disabled="true" v-model="checkDialogData.description"></el-input>
            </el-form-item>
            <el-form-item label="商家电话">
              <el-input disabled="true" v-model="checkDialogData.mobile"></el-input>
            </el-form-item>
            <!--        <el-form-item label="商家照片">-->
            <!--          <el-image-->
            <!--            v-for="(item,index) in checkDialogData.links"-->
            <!--            :key="index"-->
            <!--            style="width: 100px; height: 100px;margin-right: 10px"-->
            <!--            :src="item.link"-->
            <!--            :preview-src-list="srcList">-->
            <!--          </el-image>-->
            <!--        </el-form-item>-->
            <el-form-item style="text-align: right">
              <el-button type="primary" @click="checkDialogVisible = false">确定</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="商品信息" name="second">配置管理</el-tab-pane>
      </el-tabs>

    </el-dialog>
  </div>
</template>

<script>
import {getApplyShop,getShopByUserId} from "@/api/shop";
import {AuditGamer} from "@/api/gammer";

export default {
  name: 'Index',
  created() {
    this.fetch(this.page.currentPage, this.page.size)
  },
  data() {
    return {
      //查询相关
      selectData: {
        status:0
      },
      options: [
        {
          value: 0,
          label: '待审'
        }, {
          value: 9,
          label: '通过'
        }, {
          value: 1,
          label: '驳回'
        }],
      //查看商家相关
      checkDialogData:{},
      checkDialogVisible:false,
      activeName:"first",
      //审核弹出框相关
      auditDialogData:{},
      auditDialogVisible:false,

      //表格相关
      tableData: [],
      isLoading:false,

      //翻页相关
      page: {
        size: 10,
        currentPage: 1,
        total: 0,
      },
    }
  },
  methods: {
    async fetch(page,size,status = 0) {
      this.isLoading = true
      const res = await getApplyShop({
        page,
        size,
        status
      })

      this.tableData = res.data
      this.page.total = res.total
      console.log(res)
      this.isLoading = false
    },

    //翻页相关
    async handleSizeChange(size) {
      if (this.isSelect) {
        await this.select(this.page.currentPage, size)
      } else {
        await this.fetch(this.page.currentPage, size);
      }

    },
    async handleCurrentChange(currentPage) {
      if (this.isSelect) {
        await this.select(currentPage, this.page.size)
      } else {
        await this.fetch(currentPage, this.page.size)
      }
    },

    //查询相关
    select() {
      this.fetch(this.page.currentPage, this.page.size,this.selectData.status)
    },

    //表格相关
    auditshop(row) {
      this.auditDialogVisible = true
      this.auditDialogData = JSON.parse(JSON.stringify(row))
    },

    //审核弹出框相关
    submitAudit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          const res = await AuditGamer({
            id:this.auditDialogData.id,
            tag:'STORE',
            status:this.auditDialogData.is_examine
          });
          this.auditDialogVisible = false
          await this.fetch(this.page.currentPage, this.page.pageSize)
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },

    checkShop(item) {
      this.checkDialogVisible = true
      this.checkDialogData = item
      console.log(item)
    }
  }
}
</script>

<style lang="scss"scoped>
.tag{
  padding: 10px;
  min-height: 100vh;
}
.head {
  display: flex;
  justify-content: space-between;
  background-color: white;
  margin-top: 10px;
  padding: 30px 10px 10px 10px;
  border-radius: 10px;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
.body{
  padding: 20px 0px;
  background-color: white;
  margin-top: 20px;
  //padding: 10px;
  border-radius: 10px;
  overflow: hidden;
.body-page {
  text-align: center;
  margin-top: 30px;
}
}
</style>
